//
//  RunFriend_VC.m
//  Run
//
//  Created by BetaTheta on 16/4/1.
//  Copyright © 2016年 BetaTheta. All rights reserved.
//

#import "RunFriend_VC.h"
#import "RunFriendCollectionViewCell.h"
#import "RunFriendModel.h"
@interface RunFriend_VC ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation RunFriend_VC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createView];
    [self createData];
    
    self.dataArr = [NSMutableArray array];
}

- (void)createData {
    
    
    
    [MBProgressHUD showMessage:@"正在加载"];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUD];
        
    });
    
    

    
    NSDictionary *dic = @{@"Cookie": @"PHPSESSID=bje18qnaj5iltjsjad2grofa04; user_token=71ade94b-5911-4d73-803c-b121c7f28056"};
    
    [DYAFNetTool POSTNetWithUrl:@"https://api2.hotbody.cn/api/home/story/hot_story" body:@"offset=0" bodyStyle:DYRequestString headerFile:dic response:DYJSON success:^(id result) {
    
        
        self.dataArr = [RunFriendModel modelHanderWithArray:result];
        
        
        [_collectionView reloadData];
        
        
    } failure:^(NSError *error) {
        
        
    }];
    
    
    
}


- (void)createView {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(WIDTH * 3 / 7, 280);
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 10;
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 20, 10, 20);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT- 64) collectionViewLayout:flowLayout];
    _collectionView.backgroundColor = [UIColor colorWithWhite:0.600 alpha:1.000];
    
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    
    [_collectionView registerClass:[RunFriendCollectionViewCell class] forCellWithReuseIdentifier:@"RunFriendCollectionViewCellIdentifier"];
    
    [self.view addSubview:_collectionView];
    
    
}

//返回个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _dataArr.count;
}

//返回每行itme
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    RunFriendCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RunFriendCollectionViewCellIdentifier" forIndexPath:indexPath];
    cell.runFriendModel = _dataArr[indexPath.row];

    
    return cell;
}

//点击事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
